package controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bson.types.ObjectId;
import org.junit.runner.Request;

import play.cache.Cache;
import play.libs.Codec;
import play.mvc.Scope.Session;
import play.mvc.*;
import models.User;
import controllers.api.API;

public class Login extends API {
	// @Before
	/*static void checkAuthenticated() {
	    if(!session.contains("user")) {
	        login();
	    }
	}*/


	public static void login(){

	 	//	Map<String,Object> args = new HashMap<String,Object>();
		String username=request.params.get("email");
		String userpass=request.params.get("password");
		//String ss=Codec.hexMD5(userpass);
		User user = User.find("byEmailAndPassword",username,userpass).first(); 
		if(user != null){
			session.put("sessionUser",user.getId());
			json(user.getId());
		}else{
			json("Error");
		}
		
	}
}
